package dtry;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class Test03 {
    public static void main(String[] args) {
        //收集流中的数据，收集到各种集合当中
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"张三-男-18","李四-女-19","王五-男-20","赵六-女-21");
        //收集男到List集合
        List<String> l1 = list.stream()
                .filter(s -> "男".equals(s.split("-")[1]))
                .collect(Collectors.toList());
        System.out.println(l1);
        //收集到Set集合
        //可以去重
        Set<String> l2 = list.stream()
                .filter(s -> "男".equals(s.split("-")[1]))
                .collect(Collectors.toSet());
        System.out.println(l2);
        //收集到Map集合
        //收集所有男性
        //键：姓名，值：年龄
        //不能重复
        list.stream()
                .filter(s -> "男".equals(s.split("-")[1]))
                .collect(Collectors.toMap(s -> s.split("-")[0], s -> Integer.parseInt(s.split("-")[2])))
                .forEach((k,v) -> System.out.println(k + "==" + v));
    }
}
